Completed
Push — master ( 12029f...68e9ab )
by Maxence
02:26
created

resultMembers.removeMemberResult   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
/*
2
 * Circles - Bring cloud-users closer together.
3
 *
4
 * This file is licensed under the Affero General Public License version 3 or
5
 * later. See the COPYING file.
6
 *
7
 * @author Maxence Lange <[email protected]>
8
 * @copyright 2017
9
 * @license GNU AGPL version 3 or any later version
10
 *
11
 * This program is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU Affero General Public License as
13
 * published by the Free Software Foundation, either version 3 of the
14
 * License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU Affero General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU Affero General Public License
22
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23
 *
24
 */
25
26
/** global: OC */
27
/** global: OCA */
28
/** global: Notyf */
29
30
/** global: actions */
31
/** global: nav */
32
/** global: elements */
33
/** global: curr */
34
/** global: api */
35
36
37
var resultMembers = {
38
39
40
	searchMembersResult: function (response) {
41
42
		elements.membersSearchResult.children().remove();
43
44
		if (response === null) {
45
			elements.membersSearchResult.fadeOut(0);
46
			return;
47
		}
48
49
		elements.fillMembersSearch('users', response.ocs.data.exact.users, response.ocs.data.users);
50
		elements.fillMembersSearch('groups', response.ocs.data.exact.groups, response.ocs.data.groups);
51
52
		if (elements.membersSearchResult.children().length === 0)
53
		{
54
			elements.membersSearchResult.fadeOut(0);
55
			return;
56
		}
57
58
		$('.members_search').on('click', function () {
59
			if ($(this).attr('source') === 'groups')
60
			{
61
				api.addGroupMembers(curr.circle, $(this).attr('searchresult'),
62
					resultMembers.addGroupMembersResult);
63
			} else {
64
				api.addMember(curr.circle, $(this).attr('searchresult'),
65
					resultMembers.addMemberResult);
66
			}
67
		});
68
		elements.membersSearchResult.fadeIn(300);
69
	},
70
71
72
	addMemberResult: function (result) {
73
74
		if (result.status === 1) {
75
			OCA.notification.onSuccess(
76
				t('circles', "Member '{name}' successfully added to the circle",
77
					{name: result.name}));
78
79
			nav.displayMembers(result.members);
80
			return;
81
		}
82
		OCA.notification.onFail(
83
			t('circles', "Member '{name}' could not be added to the circle", {name: result.name}) +
84
			': ' +
85
			((result.error) ? result.error : t('circles', 'no error message')));
86
	},
87
88
	addGroupMembersResult: function (result) {
89
90
		if (result.status === 1) {
91
			OCA.notification.onSuccess(
92
				t('circles', "Members from group '{name}' successfully added to the circle",
93
					{name: result.name}));
94
95
			nav.displayMembers(result.members);
96
			return;
97
		}
98
		OCA.notification.onFail(
99
			t('circles', "Members from group '{name}' could not be added to the circle", {name: result.name}) +
100
			': ' +
101
			((result.error) ? result.error : t('circles', 'no error message')));
102
	},
103
104
105
	removeMemberResult: function (result) {
106
		if (result.status === 1) {
107
108
			elements.rightPanel.fadeOut(300);
109
			elements.mainUIMembersTable.children("[member-id='" + result.name + "']").each(
110
				function () {
111
					$(this).hide(300);
112
				});
113
			OCA.notification.onSuccess(
114
				t('circles', "Member '{name}' successfully removed from the circle",
115
					{name: result.name}));
116
			return;
117
		}
118
119
		OCA.notification.onFail(
120
			t('circles', "Member '{name}' could not be removed from the circle",
121
				{name: result.name}) +
122
			': ' +
123
			((result.error) ? result.error : t('circles', 'no error message')));
124
	},
125
126
	levelMemberResult: function (result) {
127
		if (result.status === 1) {
128
			OCA.notification.onSuccess(
129
				t('circles', "Member '{name}' updated",
130
					{name: result.name}));
131
132
			nav.displayMembers(result.members);
133
			return;
134
		}
135
136
		nav.displayMembers('');
137
		OCA.notification.onFail(
138
			t('circles', "Member '{name}' could not be updated", {name: result.name}) +
139
			': ' +
140
			((result.error) ? result.error : t('circles', 'no error message')));
141
	}
142
143
};
144